package com.ysd.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ysd.entity.NewsDetails;
import com.ysd.util.DBManager;

public class TuJianChaDaoImpl {

	public List<NewsDetails> getNewsList(){
		//创建集合
		List<NewsDetails> nedList = new ArrayList<NewsDetails>();
		//创建连接
		Connection conn = DBManager.getConnection();
		//全局变量
		Statement st = null;
		ResultSet rs = null;
		
		try {//
			st = conn.createStatement();
			rs = st.executeQuery("select * from newsdetails order by rand() limit 4");
			while(rs.next()) {
				int newsDetailsId = rs.getInt("newsDetailsId");
				String title = rs.getString("title");
				String introduction = rs.getString("introduction");
				String content = rs.getString("content");
				int newsClassifyId = rs.getInt("newsClassifyId");
				NewsDetails ndsList = new NewsDetails(newsDetailsId, title, introduction, content, newsClassifyId);
				nedList.add(ndsList);
			}
			return nedList;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} finally {
			DBManager.closeAll(conn, st, rs);
		}
	}
}
